import React from 'react'
import { View, Image } from 'react-native'
import { Jx, Jpp, Lt, Nav, Color, Label, Dialog } from "../_utils"
import { Net, NET_GET } from "../_net"
import { eApp, eSort, cHome } from '../home/_home';
import { GoodsList } from './ApplyGoodsList';
import { SortBar } from '../home/SortBar';


export class ApplyMajor extends React.PureComponent{
    constructor(props){
        super(props);
        const {opt} = this.props.navigation.state.params;
        this.opt = opt;
        this.info = eSort.defaultInfo;
        this.goodslist = null;

        this.onSort = this.onSort.bind(this);
        this.onLoad = this.onLoad.bind(this);
    }
    static navigationOptions = ({navigation, screenProps})=>({
        ...Nav.options,
        headerTitle:navigation.state.params.title,
    })
    
    onSort(info){
        this.info = info;
        this.goodslist && this.goodslist.refresh();
    }
    onLoad(params){
        Net.request("taobao/opt?opt="+ this.opt + "&" + params.pageStr + "&sort=" + this.info.index, null, {NET_GET, params}).then(r=>{
            if(r.data){
                params.add(r.data.data);
            }else{
                params.add();
            }
        });
    }
    render(){
        return <View style = {{flex:1, }}>
            <Nav.StatusBar />
            <SortBar fields={["综合", "热度", "销量", "超优惠"]} onSort={this.onSort}/>
            <GoodsList
                appIdx = {eApp.rdxs[eApp.TB]}
                onLoad = {this.onLoad}
                ref={r=>this.goodslist=r}
            />
        </View>
    }
}


